package com.youbug.kefu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youbug.kefu.entity.User;
import com.youbug.kefu.mapper.UserMapper;
import com.youbug.kefu.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youbug.kefu.vo.UserVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author sunwx
 * @since 2022-12-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Override
    public IPage<User> getUserPage(UserVo userVo) {

        Page<User> userPage = new Page<>();

        userPage.setCurrent(userVo.getCurrentPage());

        userPage.setSize(userVo.getPageSize());

        QueryWrapper<User> wrapper = new QueryWrapper<>();

        if(StringUtils.hasText(userVo.getUsername())){

            wrapper.eq("username", userVo.getUsername());
        }

        if(StringUtils.hasText(userVo.getGender())){

            wrapper.eq("gender", userVo.getGender());
        }

        Page<User> page = this.page(userPage, wrapper);

        return page;
    }
}
